{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "\n",
    "import random"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "# deck and cl is actually one thing\n",
    "\n",
    "class Deck:\n",
    "    \n",
    "    def __init__(self, deck=[], available=0, name=\"d\"):\n",
    "        self.deck = deck\n",
    "        self.available = available # available: 0 not available, 1 only top, 2 full\n",
    "        self.name = name\n",
    "        \n",
    "    def shuffle(self):\n",
    "        random.shuffle(self.deck)\n",
    "        \n",
    "    def __repr__(self):\n",
    "        cards = \"\"\n",
    "        if self.available == 0:\n",
    "            cards = \"\"\n",
    "        elif self.available == 1 and self.deck:\n",
    "            cards = \"TopCard: {}\".format(self.deck[0].content)\n",
    "        else:\n",
    "            cards = \"Cards: \\n{}\".format(\"\\n\".join([str(i)+\": \"+c.content for i,c in enumerate(self.deck)]))\n",
    "        return \"Deck: {}\\n{}\\n\".format(self.name, cards)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "class Card:\n",
    "    \n",
    "    def __init__(self, content=\"\", state={}):\n",
    "        self.content = content\n",
    "        self.state = state"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "def move(deck1, idx, deck2):\n",
    "    if deck1.deck:\n",
    "        deck2.deck.append(deck1.deck.pop(idx))\n",
    "    else:\n",
    "        print(\"No cards!\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "# \"m\" needs some parsing, if the second one is not a number, then simply move the top.\n",
    "\n",
    "def simple_parsing(command, decks):\n",
    "    args = command.split()\n",
    "    times = 1\n",
    "    if args[0].isdigit():\n",
    "        times = int(args.pop(0))\n",
    "    for i in range(times):\n",
    "        if args[0] in [\"m\",\"mv\"]:\n",
    "            if args[2].isdigit():\n",
    "                move(decks[args[1]], int(args[2]), decks[args[3]])\n",
    "            else:\n",
    "                move(decks[args[1]], 0, decks[args[2]])\n",
    "        elif args[0] == \"sh\":\n",
    "            decks[args[1]].shuffle()\n",
    "        elif args[0] == \"p\":\n",
    "            print(decks[args[1]][int(args[2])])\n",
    "\n",
    "# TODO: get the function, and the creation, and can setup without touching the code"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "def run(decks):\n",
    "    rounds = 0\n",
    "    while True:\n",
    "        print(\"\\n## Round:\", rounds)\n",
    "        print()\n",
    "\n",
    "        for d in decks:\n",
    "            print(decks[d])\n",
    "\n",
    "        command = input()\n",
    "\n",
    "        simple_parsing(command, decks)\n",
    "        rounds += 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "dominion_kingdoms = [\n",
    "    \"Cellar 2: +1 A, Discard X, Draw X\",\n",
    "    \"Village 3: +2 A, +1 C\",\n",
    "    \"Workshop 3: Gain a card costing up to 4\",\n",
    "    \"Remodel 4: Trash a card, gain a card costing up to 2 more\",\n",
    "    \"Smithy 4: +3 C\",\n",
    "    \"Throne room 4: Play an action card twice\",\n",
    "    \"Lab 5: +2 C, +1 A\"\n",
    "    \"Market 5: +1 C, +1 A, +1 B, +1 $\",\n",
    "]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "dominion_basics = [\n",
    "    \"$2 3\",\n",
    "    \"$3 6\",\n",
    "    \"3VP 5\",\n",
    "    \"6VP 8\",\n",
    "]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "dominion_setup = [\"$1\" for i in range(7)]+[\"1VP\" for i in range(3)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "decks = {}\n",
    "for i,k in enumerate(dominion_kingdoms):\n",
    "    decks[\"C\"+str(i)] = Deck([Card(k) for i in range(10)], 1, \"C\"+str(i)) # EH: name should not be represented twice, actually list to dict is a solution for this\n",
    "for i,b in enumerate(dominion_basics):\n",
    "    decks[\"B\"+str(i)] = Deck([Card(b) for i in range(8)], 1, \"B\"+str(i))\n",
    "decks[\"d\"] = Deck([Card(b) for b in dominion_setup], 0, \"d\")\n",
    "decks[\"h\"] = Deck([], 2, \"h\")\n",
    "decks[\"e\"] = Deck([], 1, \"e\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
